package cn.bdqn.hospital.controller;

import cn.bdqn.hospital.service.EmployeesService;
import cn.bdqn.hospital.service.impl.EmployeesServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/employees.do")
public class EmployeesServlet extends HttpServlet {
    private EmployeesService employeesService = new EmployeesServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try{
            String opr = req.getParameter("opr");

        } catch (Exception e){
            throw new ServletException(e.getMessage());
        }
    }

    /**
     * 登录
     * @param req
     * @param resp
     * @throws Exception
     */
    public void login(HttpServletRequest req, HttpServletResponse resp) throws Exception{
        HttpSession session = req.getSession();
        // 接受表单数据
        String ygAccount = req.getParameter("ygAccount");
        String ygpassword = req.getParameter("ygpassword");
        // 模拟service返回结果
        int loginEmployees = employeesService.deleteByYgAccount(ygAccount);
        if (loginEmployees == 0){
            req.setAttribute("loginError","账号不存在!");
            req.getRequestDispatcher("/index.jsp").forward(req,resp);
        }
    }
}
